package com.woniuxy.lab.woniu_lab_boss.controller;


import com.woniuxy.lab.woniu_lab_boss.common.Result;
import com.woniuxy.lab.woniu_lab_boss.controller.form.LoginForm;
import com.woniuxy.lab.woniu_lab_boss.service.AccountService;
import com.woniuxy.lab.woniu_lab_boss.service.dto.AccountDto;
import com.woniuxy.lab.woniu_lab_boss.util.Demo;
import com.woniuxy.lab.woniu_lab_boss.util.WebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.security.AuthProvider;

/**
 * <p>
 * 账户表 前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/account")
@Api(tags = "[A]账户(后台)相关接口")
@Slf4j
@Validated
public class AccountController {
    @Resource
    private AccountService accountService;
    @Resource
    private Demo demo;



    /**
     * 账号密码登录
     * @param form 登录参数
     * @return null
     */
    @ApiOperation("59 后台登录")
    @PostMapping("/login")
    @ApiResponse(code = 200, message = "返回admin或teacher 用于判断", response = String.class)
    public Result<String> login(@RequestBody @Valid LoginForm form){
        String[] typeAndToken =  accountService.login(form);
        return Result.success(200, typeAndToken[0], typeAndToken[1]);
    }

    /**
     * 查询账号信息
     * @return null
     */
    @ApiOperation("95 查询账号信息")
    @PostMapping("/getAccountInfo")
    @ApiResponse(code = 200, message = "返回AccountDto（包含用户名以及type）", response = String.class)
    public Result<AccountDto> getAccountInfo(){
        AccountDto accountDto=  accountService.findByToken();
        return Result.success(200, "查询账号信息成功",accountDto);
    }




}

